package com.cungmua.app.task;

import android.content.Context;

import com.cungmua.app.handler.BaseAuthenticatedRequestHandler;
import com.cungmua.app.handler.ProfileHandler;
import com.cungmua.app.model.request.ProfileRequest;
import com.cungmua.app.model.response.ProfileResponse;
import com.cungmua.app.net.CungMuaAPI;

import retrofit.RetrofitError;

/**
 * Created by kelvin.nguyen on 7/1/14.
 */
public class ProfileTask extends AuthenticatedTask<ProfileRequest, Void, ProfileResponse> {
    private Context context;
    private ProfileHandler handler;

    public ProfileTask(Context context, ProfileHandler handler) {
        this.context = context;
        this.handler = handler;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected ProfileResponse doInBackground() throws RetrofitError {
        ProfileRequest request = params[0];

        return CungMuaAPI.getService().getProfile(request.toFieldMap());
    }

    @Override
    protected BaseAuthenticatedRequestHandler getHandler() {
        return handler;
    }

    @Override
    protected void onSuccess(ProfileResponse profileResponse) {
        handler.onProfile(profileResponse);
    }
}
